import wx

class alertBox(wx.Dialog):
	def __init__(self, prnt, text, info='', tpBtn=(), default=0):
		wx.Dialog.__init__(self, prnt, style=wx.CAPTION | wx.SYSTEM_MENU)
		self.SetBackgroundColour((255,255,255))
		self.SetMinSize((400,20))
		
		try:
			bmpAlert = wx.Bitmap('icons/global/alert.gif')
		except:
			bmpAlert = None
			
		self.sbIcon = wx.StaticBitmap(self, bitmap=bmpAlert)
		self.stText = wx.StaticText(self, -1, text)
		self.stText.SetFont(wx.Font(9, wx.DEFAULT, wx.NORMAL, wx.FONTWEIGHT_BOLD))
		
		self.stInfo = wx.StaticText(self, -1, info)
		self.stInfo.SetFont(wx.Font(8, wx.DEFAULT, wx.NORMAL, wx.NORMAL))
		
		self.lstBtns = []
		ls = len(tpBtn)
		if ls == 0:
			tpBtn = ('&OK',)
			ls = 1
			
		for x in range(0, ls):
			self.lstBtns.append(wx.Button(self, -1, tpBtn[x]))
			self.lstBtns[-1].Number = x
			self.lstBtns[-1].Bind(wx.EVT_BUTTON, self.onButton)
				
		wrapWidth = 0
		for x in self.lstBtns:
			wrapWidth += x.GetSize()[0]
		
		wrapWidth += 36
		
		if wrapWidth < 300: wrapWidth = 300
		
		self.stText.Wrap(wrapWidth)
		self.stInfo.Wrap(wrapWidth)

		sizer = wx.BoxSizer(wx.VERTICAL)
		
		sizer.Add(self.stText, 0, wx.BOTTOM, 8)
		sizer.Add(self.stInfo, 0, wx.BOTTOM, 8)
		
		btnsizer = wx.BoxSizer(wx.HORIZONTAL)
		
		for x in range(0, len(self.lstBtns)):			
			flags = (wx.LEFT | wx.ALIGN_RIGHT, wx.LEFT | wx.ALIGN_RIGHT, wx.RIGHT)
			btnsizer.Prepend(self.lstBtns[x], 0, flags[x], 12)
			
		if ls == 3:
			btnsizer.InsertStretchSpacer(1, 1)
		else:
			btnsizer.PrependStretchSpacer(1)
			
		sizer.Add(btnsizer, 0, wx.EXPAND | wx.TOP | wx.ALIGN_RIGHT, 15)
		
		mainsizer = wx.BoxSizer(wx.HORIZONTAL)
		mainsizer.Add(self.sbIcon, 0, wx.LEFT | wx.TOP, 20)
		mainsizer.Add(sizer, 0, wx.ALL, 20)
		self.SetSizer(mainsizer)
		self.Fit()
		
		if (ls - 1) < default:
			self.lstBtns[0].SetFocus()
		else:
			self.lstBtns[default].SetFocus()
			
		self.ShowModal()
		
	def onButton(self, event):
		self.SetReturnCode(event.GetEventObject().Number)
		self.Destroy()
	
#a = wx.PySimpleApp()
#dlg = alertBox(None, 'Are you sure you want to reset the preferences file?', 'This action cannot be undone.', ('test','test2','test3'), 1)
#print(dlg.ShowModal())
#a.MainLoop()